﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace theguineasyndrome
{
    public class Bee : Enemy
    {
        private Vector2 initialPosition;
        private Texture2D ropeTexture;

        public Bee(Level level, Texture2D texture, Texture2D ropeTexture, Vector2 position)
            : base(level, texture, position)
        {
            initialPosition = position;
            this.ropeTexture = ropeTexture;
            collisionRectangle = new Rectangle(0, 10, texture.Width, texture.Height - 10);
        }

        public override bool canBurn()
        {
            return false;
        }

        public override void Update(GameTime gameTime)
        {
            double t = gameTime.TotalGameTime.TotalMilliseconds / 500;
            Position = new Vector2((float)(initialPosition.X + Math.Cos(t) * 150), initialPosition.Y);
            direction = -Math.Sign(Math.Sin(t));
        }

        public override void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            SpriteEffects effects = SpriteEffects.None;

            if (direction < 0)
                effects |= SpriteEffects.FlipHorizontally;

            spriteBatch.Draw(texture, camera.getDstRect(rectangle), null, Color.White, 0, spriteOrigin, effects, 0);

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone);

            Rectangle ropeRectangle = new Rectangle(0, 0, ropeTexture.Width, 0);
            Vector2 ropeNode = Center + new Vector2(0, -9);
            ropeRectangle.X = (int)(camera.getDstPoint(ropeNode).X - ropeTexture.Width / 2);
            ropeRectangle.Height = (int)camera.getDstPoint(ropeNode).Y;
            Rectangle ropeSrcRect = new Rectangle(0, 0, ropeTexture.Width, ropeRectangle.Height);
            spriteBatch.Draw(ropeTexture, ropeRectangle, ropeSrcRect, Color.White);

            spriteBatch.End();
            spriteBatch.Begin();
        }
    }
}
